package com.gxc.chain;

import com.gxc.filter.UserParamFilter;
import com.gxc.model.User;
import com.gxc.model.UserEo;

import java.util.List;

/**
 * @author GongXincheng
 * @date 2021/8/16 14:20
 */
public class UserParamFilterChain {

    private final int size;

    private int currentIndex;

    private final List<UserParamFilter> filterList;

    public UserParamFilterChain(List<UserParamFilter> filterList) {
        this.filterList = filterList;
        this.size = filterList.size();
    }

    public void filter(UserEo userEo, User user) {
        if (currentIndex == size) {
            return;
        }
        UserParamFilter userParamFilter = filterList.get(currentIndex);
        currentIndex++;
        userParamFilter.filter(userEo, user, this);
    }

}
